package com.edu.edu.day25_homework.fragment;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

/**
 * Created by Administrator on 2016/9/10.
 */
public class FragmentFactory {

    private static final int MOVIE = 0;
    private static final int SHOW = 1;
    private static final int FIND = 2;
    private static final int ME = 3;

    private static SparseArray<Fragment> fragments = new SparseArray<>();

    public static Fragment createFragment(int index){
        Fragment fragment = fragments.get(index);
        if(fragment == null){
            switch (index){
                case MOVIE:
                    fragment = new MovieFragment();
                    break;
                case SHOW:
                    fragment = new ShowFragmen();
                    break;
                case FIND:
                    fragment = new FindFragmen();
                    break;
                case ME:
                    fragment = new MeFragment();
                    break;
            }
            fragments.put(index,fragment);
        }
        return fragment;
    }
}
